﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using CFScript;

namespace CFScript_Client
{
    public partial class Form1 : Form
    {
        CFScript.CFScript script;

        public Form1()
        {
            InitializeComponent();
        }

        private void menuItem4_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void menuItem2_Click(object sender, EventArgs e)
        {
            try
            {
                openFileDialog1.Filter = "CompactFramework Script Files|*.cfs|Todos los archivos|*.*";
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    script = new CFScript.CFScript(openFileDialog1.FileName);
                    listBox1.Items.Add("Script loaded");
                }
            }
            catch (Exception ex)
            {
                listBox1.Items.Add("Error: " + ex);
            }
        }

        private void menuItem3_Click(object sender, EventArgs e)
        {
            if (this.script != null)
            {
                this.listBox1.Items.Clear();
                ScriptResult sr = this.script.Execute(Console.Out); 
                this.listBox1.Items.Add("Code: " + sr.Code);
                this.listBox1.Items.Add("Message: " + sr.Message);

            }
            else
            {
                this.listBox1.Items.Add("Error: No script loaded");
            }
        }
    }
}